import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useCartStore = defineStore(
  'cart',
  () => {
    const selectedItems = ref({})

    const setSelected = (id, isSelected) => {
      selectedItems.value[id] = isSelected
    }

    const isItemSelected = (id) => {
      return selectedItems.value[id] || false
    }

    const clearSelection = () => {
      selectedItems.value = {}
    }

    return {
      selectedItems,
      setSelected,
      isItemSelected,
      clearSelection
    }
  },
  {
    persist: true
  }
)
